package ber.mcs;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
 
import android.util.Log;
 
public class Client {
        
        public void enviar(String pacote) {
                try {
                        // Retrieve the ServerName
                        InetAddress serverAddr = InetAddress.getByName("192.168.4.97");
                       
                        Log.d("UDP", "C: Connecting...");
                        /* Create new UDP-Socket */
                        DatagramSocket socket = new DatagramSocket();
                       
                        /* Prepare some data to be sent. */
                        byte[] outData = (pacote).getBytes();
                       
                        /* Create UDP-packet with
                         * data & destination(url+port) */
                        DatagramPacket packet = new DatagramPacket(outData, outData.length,     serverAddr, 1235);
                        Log.d("UDP", "C: Sending: '" + new String(outData) + "'");
                       
                        /* Send out the packet */
                 
                        socket.send(packet);
                        Log.d("UDP", "C: Sent.");
                        Log.d("UDP", "C: Done.");
                } catch (Exception e) {
                        Log.e("UDP", "C: Error", e);
                }
        }
}
